package pkg

import (
	"time"
	"wx/appconfig"

	"github.com/dgrijalva/jwt-go"
)

const (
// APP_KEY = "www.topgoer.com"
)

func TokenHandler(userId string) (string, error) {
	// 颁发一个有限期一小时的证书
	token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
		"useId": userId,
		"exp":   time.Now().Add(time.Hour * time.Duration(1)).Unix(),
		"iat":   time.Now().Unix(),
	})
	tokenString, err := token.SignedString([]byte(appconfig.Appconf.Jwt.APP_KEY))
	return tokenString, err
}
